package net.huashitong.Indicators.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.sirdc.modules.utils.NumberUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Indicators.entity.MonthlyCount;
import net.huashitong.Indicators.filter.MonthlyCountFilter;
import net.huashitong.Indicators.service.MonthlyCountService;
import net.huashitong.Indicators.service.TertiaryIndustryService;
import net.huashitong.Indicators.utils.DataFormateUntil;
import net.huashitong.Indicators.utils.DataUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;

@Controller
@RequestMapping("/app/MonthlyCount/")
public class MonthlyCountController extends JsonBaseController {

	@Autowired
	private MonthlyCountService MonthlyCountService;
	@Autowired
	private TertiaryIndustryService tertiaryIndustryService;


	public static final String[] months = {"12", "11", "10", "09", "08", "07", "06", "05", "04", "03", "02", "01"};
	public static final String[] years = {"2018", "2017"};
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@ResponseBody
	@RequestMapping("/getName")
	public Message queryIndName(@RequestBody MonthlyCountFilter filter) {
		List list = MonthlyCountService.getIndName(filter.getAab001());
		//System.out.println("sslist:"+list);
		List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();

		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			Object[] ob = (Object[]) list.get(i);

			map.put("typeID", ob[1].toString());
			map.put("typename", ob[2].toString());
			map.put("indID", ob[4].toString());
			map.put("indName", ob[0].toString());
			lists.add(map);
		}
		//Map<String, Object> maps =new HashMap<String, Object>();
		//maps.put(arg0, arg1)
		return coverMessage("200", "获取成功", lists);
	}

	@ResponseBody
	@RequestMapping("/getIndInfo")
	public Message queryIndInfo(@RequestBody MonthlyCountFilter filter) {
		String month = "";

		String bab001 = filter.getBab001();
		if (filter.getBab001() == null || filter.getBab001().equals("")) {
			List str = MonthlyCountService.getnewMon(filter.getAab005());
			month = str.get(0).toString();//获取最新月份
		}

		List<MonthlyCount> lists = MonthlyCountService.getIndInfo(filter.getAab005(), bab001.equals("") ? month : bab001);
		List<Map<String, Object>> monCounts = new ArrayList<Map<String, Object>>();
		for (MonthlyCount list : lists) {
			Map<String, Object> map = new HashMap<String, Object>();
			//TertiaryIndustry terInd = tertiaryIndustryService.getUint(list.getAab005());
			if ("万元".equals(list.getBab002())) {
				map.put("cumlative", list.getAab009() == null || list.getAab009().toString().equals("") ?
						"0" : DataFormateUntil.dataformatUnit(list.getAab009()));
				map.put("expectionJob", list.getAab008() == null || list.getAab008().toString().equals("") ?
						"0" : DataFormateUntil.dataformatUnit(list.getAab008()));

				map.put("unit", "亿元");

			}
			if ("万美元".equals(list.getBab002())) {
				map.put("cumlative", list.getAab009() == null || list.getAab009().toString().equals("") ?
						"0" : DataFormateUntil.dataformatUnit(list.getAab009()));
				map.put("expectionJob", list.getAab008() == null || list.getAab008().toString().equals("") ?
						"0" : DataFormateUntil.dataformatUnit(list.getAab008()));

				map.put("unit", "亿美元");
			}
			if ("亿元".equals(list.getBab002())) {
				map.put("cumlative", list.getAab009() == null || list.getAab009().toString().equals("") ?
						"0" : DataFormateUntil.dataFormat(list.getAab009()));
				map.put("expectionJob", list.getAab008() == null || list.getAab008().toString().equals("") ? "0" : DataFormateUntil.dataFormat(list.getAab008()));
				map.put("unit", list.getBab002());
			}

			map.put("typeID", list.getAab001());
			map.put("indID", list.getAab005());
			map.put("projectCount", DataUtils.isEmpty(list.getBab004(), "0"));
			map.put("projectCountName", list.getBab005());

			map.put("indName", list.getAab004());
			map.put("area", list.getAab007() == null || list.getAab007().toString().equals("") ? "" : list.getAab007());
			//map.put("expectionJob", list.getAab008()==null||list.getAab008().toString().equals("")?"0": DataFormateUntil.dataFormat(list.getAab008()) );
			//map.put("cumlative",list.getAab009()==null||list.getAab009().toString().equals("")?"0":DataFormateUntil.dataFormat(list.getAab009()));
			map.put("ratio", list.getAab010() == null || list.getAab010().toString().equals("") ? "0" : DataFormateUntil.dataFormat(list.getAab010()));
			map.put("achieveJob", list.getAab011() == null || list.getAab011().toString().equals("") ? "0" : DataFormateUntil.dataFormat(list.getAab011()));
			map.put("ratioRank", list.getAab012());
			map.put("achieveRank", list.getAab013());
			monCounts.add(map);
		}
		Map<String, Object> savemaps = new HashMap<String, Object>();
		savemaps.put("currentTime", bab001.equals("") ? month.substring(0, 4) + "年" + month.substring(month.length() - 2, month.length()) + "月" : filter.getBab001().substring(0, 4) + "年" + filter.getBab001().substring(filter.getBab001().length() - 2, filter.getBab001().length()) + "月");
		savemaps.put("list", monCounts);
		return coverMessage("200", "获取成功", savemaps);
	}

	/**
	 * 统计
	 *
	 * @param filter
	 * @return
	 */

	@ResponseBody
	@RequestMapping("/getCountData")
	public Message getCount(@RequestBody MonthlyCountFilter filter) {
		String newmonth = "";
		if ("".equals(filter.getBab001())) {
			List strs = MonthlyCountService.getNewMonth(filter.getAab001());
			newmonth = strs.get(0).toString();
		}
		List<MonthlyCount> lists = MonthlyCountService.getInfoCount(filter.getAab001(), filter.getAab003(), "".equals(filter.getBab001()) ? newmonth : filter.getBab001());
		List<Map<String, Object>> monCounts = new ArrayList<Map<String, Object>>();

		Map<String, List<MonthlyCount>> maplist = new HashMap<String, List<MonthlyCount>>();//分类数据hb003
		Map<String, String> mapclass = new HashMap<String, String>();//hb003分类
		List<Map<String, Object>> Hb003s = new ArrayList<Map<String, Object>>();

		Map<String, List<MonthlyCount>> hb02list = new HashMap<String, List<MonthlyCount>>();//分类数据hb003
		Map<String, String> hb02class = new HashMap<String, String>();//hb002分类
		List<Map<String, Object>> Hb002s = new ArrayList<Map<String, Object>>();

		Map<String, Object> HB005s = new HashMap<String, Object>();
		String tempCum = "0";//存放临时变量
		String tempname = "";//存放临时名称
		for (MonthlyCount mc : lists) {
			Map<String, Object> map = new HashMap<String, Object>();
			if ("HB004".equals(mc.getAab001()) || "HB001".equals(mc.getAab001()) || "HB011".equals(mc.getAab001()) || "HB012".equals(mc.getAab001()) || "HB013".equals(mc.getAab001()) || "HB010".equals(mc.getAab001())) {
				if (("".equals(mc.getAab005()) || mc.getAab005() == null) && ("".equals(mc.getAab009()) || mc.getAab009() == null)) {
					continue;
				}
				map.put("oneClassID", mc.getAab003());//一级分类名
				map.put("oneClassName", DataUtils.isEmpty(mc.getAab004(), "-"));//一级分类名称
				map.put("cumlation", DataFormateUntil.dataFormat(DataUtils.isEmpty(mc.getAab009(), "0")));//累计值到当前月
				map.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty(mc.getAab010(), "0")));//比增
				map.put("lastYearMonth", DataUtils.isEmpty(mc.getAab014(), "-"));//去年同期
				map.put("lastYeatMonthCumlation", DataUtils.isEmpty(mc.getAab015(), "-"));//去年同期累计
				map.put("monthCumlation", DataUtils.isEmpty(mc.getAab016(), "-"));//当月累计
				map.put("untit", DataUtils.isEmpty(mc.getBab002(), "-"));
				map.put("ratioByMonth", DataFormateUntil.dataFormat(DataUtils.isEmpty(mc.getAab017(), "0")));
				map.put("type", mc.getBab003());
				//分类的判断
				if (mc.getAab005() == null || mc.getAab005().equals("")) {
					tempCum = mc.getAab009().trim();
					tempname = mc.getAab002().trim();
				} else if (mc.getAab005().length() == 10) {
					map.put("tempcum", tempCum);
					map.put("tempname", tempname);
					map.put("type", mc.getBab003());
					map.put("twoClassID", mc.getAab005());//二级分类ID
					map.put("twoClassName", DataUtils.isEmpty(mc.getAab006().trim(), "-"));//二级分类名称
				} else if (mc.getAab005().length() == 12) {
					map.put("type", mc.getBab003());
					map.put("twoClassID", mc.getAab005());//二级分类ID
					map.put("twoClassName", DataUtils.isEmpty(mc.getAab006().trim(), "-"));//二级分类名称
					map.put("tempcum", tempCum);
					map.put("tempname", tempname);
				}
			} else if ("HB005".equals(mc.getAab001())) {
				//针对居民消费物价数据处理

				if ("HB005001".equals(mc.getAab003())) {
					HB005s.put("compLastMonth", DataFormateUntil.dataFormat(mc.getAab014()));
					HB005s.put("compLastMonthName", "环比");
					HB005s.put("compLastYear", DataFormateUntil.dataFormat(mc.getAab015()));
					HB005s.put("compLastYearName", "同比");

					HB005s.put("avg", DataFormateUntil.dataFormat(mc.getAab017()));
					HB005s.put("avgName", "累计同比");
					HB005s.put("oneClassID", mc.getAab003());//一级分类名
					HB005s.put("oneClassName", DataUtils.isEmpty(mc.getAab004(), "-"));//一级分类名称
				} else {

					map.put("compLastMonth", DataFormateUntil.dataFormat(mc.getAab014()));
					map.put("compLastMonthName", "环比");
					map.put("compLastYear", DataFormateUntil.dataFormat(mc.getAab015()));
					map.put("compLastYearName", "同比");
					map.put("avg", DataFormateUntil.dataFormat(mc.getAab017()));
					map.put("avgName", "累计同比");
					map.put("oneClassID", mc.getAab003());//一级分类名
					map.put("oneClassName", DataUtils.isEmpty(mc.getAab004(), "-"));//一级分类名称
				}


			}
			//HB003处理
			else if ("HB003".equals(mc.getAab001())) {

				if (mapclass.isEmpty()) {
					mapclass.put(mc.getAab003(), mc.getAab003());
				} else {
					if (!mc.getAab003().equals(mapclass.get(mc.getAab003()))) {
						mapclass.put(mc.getAab003(), mc.getAab003());
					}
				}
				if (maplist.get(mc.getAab003()) == null) {
					List<MonthlyCount> listmon = new ArrayList<MonthlyCount>();
					listmon.add(mc);
					maplist.put(mc.getAab003(), listmon);
				} else {
					List<MonthlyCount> lis = maplist.get(mc.getAab003());
					lis.add(mc);
					//	maplist.put(mc.getAab003(),listmon);
				}

			}
			//HB002处理
			else if ("HB002".equals(mc.getAab001())) {
				String aab005 = mc.getAab005().trim().substring(0, 10);//
				if (hb02class.isEmpty()) {
					hb02class.put(aab005, aab005);
				} else {
					if (!aab005.equals(hb02class.get(aab005))) {
						hb02class.put(aab005, aab005);
					}
				}
				//归类
				if (hb02list.get(aab005) == null) {
					List<MonthlyCount> listmon = new ArrayList<MonthlyCount>();
					listmon.add(mc);
					hb02list.put(aab005, listmon);
				} else {
					List<MonthlyCount> lis = hb02list.get(aab005);
					lis.add(mc);
				}


			}
			//剩下的处理
			else {
				map.put("oneClassID", mc.getAab001());
				map.put("oneClassName", mc.getAab002());
				map.put("twoClassID", mc.getAab003());//二级分类ID
				map.put("twoClassName", DataUtils.isEmpty(mc.getAab004().trim(), "-"));//二级分类名称
				map.put("cumlation", DataUtils.isEmpty(mc.getAab009(), "0"));
				map.put("ratio", DataUtils.isEmpty(mc.getAab010(), "-"));
				map.put("untit", mc.getBab002());
				map.put("compLastYear", DataFormateUntil.dataFormat(DataUtils.isEmpty(mc.getAab015(), "0")));

				map.put("type", "0");
			}

			if (!map.isEmpty())
				monCounts.add(map);
			HB005s.put("lists", monCounts);

		}//for循环结尾

		//003编号的特殊分类处理
		if ("HB003".equals(filter.getAab001())) {
			//
			Collection con = mapclass.values();
			Iterator ite = con.iterator();


			while (ite.hasNext()) {
				Map<String, Object> Onemap = new HashMap<String, Object>();

				List list = new ArrayList();
				int i = 0, j = 0;
				for (MonthlyCount monCount : maplist.get(ite.next())) {
					Map<String, Object> twomap = new HashMap<String, Object>();
					Map<String, Object> temp = new HashMap<String, Object>();
					if (monCount.getAab005() == null || monCount.getAab005().equals("")) {
						temp.put("cumlation", DataUtils.isEmpty(monCount.getAab009().trim(), "0"));//累计值到当前月
						temp.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty(monCount.getAab010().trim(), "0")));//比增
						temp.put("oneClassID", monCount.getAab003());//一级分类名
						temp.put("oneClassName", DataUtils.isEmpty(monCount.getAab004(), "-"));//一级分类名称
						temp.put("type", monCount.getBab003());
						temp.put("untit", DataUtils.isEmpty(monCount.getBab002(), "-"));
						temp.put("twoClassID", monCount.getAab005());//二级分类ID
						temp.put("twoClassName", DataUtils.isEmpty(monCount.getAab006().trim(), "-"));//二级分类名称
						tempCum = monCount.getAab009().trim();
						tempname = monCount.getAab004().trim();
						list.add(temp);
						Onemap.put("lists", list);
					} else if (monCount.getAab005().length() == 10) {
						i = i + 1;

						twomap.put("cumlation", DataUtils.isEmpty(monCount.getAab009().trim(), "0"));//累计值到当前月
						twomap.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty(monCount.getAab010().trim(), "0")));//比增
						twomap.put("oneClassID", monCount.getAab003());//一级分类名
						twomap.put("oneClassName", DataUtils.isEmpty(monCount.getAab004(), "-"));//一级分类名称
						twomap.put("twoClassID", monCount.getAab005());//二级分类ID
						twomap.put("twoClassName", DataUtils.isEmpty(monCount.getAab006().trim(), "-"));//二级分类名称
						twomap.put("type", monCount.getBab003());
						twomap.put("untit", DataUtils.isEmpty(monCount.getBab002(), "-"));

						twomap.put("tempcum", tempCum);
						twomap.put("tempname", tempname);
						list.add(twomap);
						Onemap.put("lists", list);
					} else if (monCount.getAab005().length() == 12) {
						j = j + 1;
						Map<String, Object> tempmap = new HashMap<String, Object>();
						//List list =new ArrayList();
						tempmap.put("cumlation", DataUtils.isEmpty(monCount.getAab009().trim(), "0"));//累计值到当前月
						tempmap.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty(monCount.getAab010().trim(), "0")));//比增
						tempmap.put("oneClassID", monCount.getAab003());//一级分类名
						tempmap.put("oneClassName", DataUtils.isEmpty(monCount.getAab004(), "-"));//一级分类名称
						tempmap.put("twoClassID", monCount.getAab005());//二级分类ID
						tempmap.put("twoClassName", DataUtils.isEmpty(monCount.getAab006().trim(), "-"));
						tempmap.put("type", monCount.getBab003());
						//list.add(tempmap);
						twomap.put("list", list);
					}

				}

				Hb003s.add(Onemap);
			}
			return coverMessage("200", "successful", Hb003s);
			//
		}
		if ("HB002".equals(filter.getAab001())) {
			List<Map.Entry<String, String>> listIndexScore = new ArrayList<Map.Entry<String, String>>(hb02class.entrySet());
			//map按照value序排序

			Map<String, String> HB002C = new TreeMap<String, String>(new MapKeyComparator());
			HB002C.putAll(hb02class);

			Collection con = HB002C.values();
			Iterator iter = con.iterator();
			String tmpaab09 = "0";
			int i = 0;
			Map<String, Object> onemap = new HashMap<String, Object>();
			while (iter.hasNext()) {

				List list = new ArrayList();
				i = i + 1;
				for (MonthlyCount monCount : hb02list.get(iter.next())) {

					Map<String, Object> twomap = new HashMap<String, Object>();
					String aab005 = monCount.getAab005().trim().substring(0, 10);//HB002 00100
					if (aab005.substring(8).equals("00")) {
						onemap.put("cumlation", StringUtils.isBlank(monCount.getAab009())?"0": NumberUtils.keepPrecision(monCount.getAab009(),2) /*DataFormateUntil.dataformatUnit(DataUtils.isEmpty(monCount.getAab009().trim(), "0"))*/);//累计值到当前月
						onemap.put("ratio", StringUtils.isBlank(monCount.getAab010())?"0": NumberUtils.keepPrecision(monCount.getAab010(),2)/*DataFormateUntil.dataFormat(DataUtils.isEmpty(monCount.getAab010().trim(), "0"))*/);//比增
						onemap.put("oneClassID", monCount.getAab003());//一级分类名
						onemap.put("oneClassName", DataUtils.isEmpty(monCount.getAab004(), "-"));//一级分类名称
						//onemap.put("type", monCount.getBab003());
						onemap.put("untit", "亿元"/* DataUtils.isEmpty(monCount.getBab002()	, "-")*/);
						onemap.put("twoClassID", monCount.getAab005());//二级分类ID
						onemap.put("twoClassName", StringUtils.isBlank(monCount.getAab006())?"-":monCount.getAab006().trim()/*DataUtils.isEmpty(monCount.getAab006().trim(), "-")*/);
						onemap.put("currentMonth",StringUtils.isBlank(monCount.getAab016())?"0": NumberUtils.keepPrecision(monCount.getAab016(),2)/* DataFormateUntil.dataformatUnit(monCount.getAab016())*/);//本月值
						onemap.put("compLastYear",StringUtils.isBlank(monCount.getAab015())?"0": NumberUtils.keepPrecision(monCount.getAab015(),2)   /*DataFormateUntil.dataformatUnit(monCount.getAab015())*/);//上年同期累计
						tmpaab09 =StringUtils.isBlank(monCount.getAab009())?"0": NumberUtils.keepPrecision(monCount.getAab009(),2); //DataUtils.isEmpty(DataFormateUntil.dataformatUnit(monCount.getAab009().trim()), "0");
					} else {
						if (monCount.getAab005().length() == 12) {
							//List lt = new ArrayList();
							twomap.put("cumlation",StringUtils.isBlank(monCount.getAab009())?"0": NumberUtils.keepPrecision(monCount.getAab009(),2));//累计值到当前月
							twomap.put("ratio", StringUtils.isBlank(monCount.getAab010())?"0": NumberUtils.keepPrecision(monCount.getAab010(),2));//比增
							//	twomap.put("oneClassID",monCount.getAab003());//一级分类名
							//twomap.put("oneClassName",DataUtils.isEmpty(monCount.getAab004(), "-")  );//一级分类名称
							//	twomap.put("type", monCount.getBab003());
							twomap.put("untit", "亿元" /*DataUtils.isEmpty(monCount.getBab002()	, "-") */);
							twomap.put("twoClassID", monCount.getAab005());//二级分类ID
							twomap.put("twoClassName",StringUtils.isBlank(monCount.getAab006())?"-":monCount.getAab006().trim());
							twomap.put("currentMonth", StringUtils.isBlank(monCount.getAab016())?"0": NumberUtils.keepPrecision(monCount.getAab016(),2));//本月值
							twomap.put("compLastYear", StringUtils.isBlank(monCount.getAab015())?"0": NumberUtils.keepPrecision(monCount.getAab015(),2));//上年同期累计
							twomap.put("tempcum", tmpaab09);
							list.add(twomap);

						}


					}
					//onemap.put("lists"+i, list);

				}
				if (list.size() != 0) {
				 /* Collections.sort(list, new Comparator<Map<String, Object>>() {
					@Override
					public int compare(Map<String, Object> arg0,
							Map<String, Object> arg1) {
						// TODO Auto-generated method stub
						
						return arg0.get("cumlation").toString().compareTo(arg1.get("cumlation").toString());
					}
				});*/
					onemap.put("lists" + i, list);

				}

			}

			return coverMessage("200", "successful", onemap);
		}
		if ("HB005".equals(filter.getAab001())) {
			return coverMessage("200", "获取成功", HB005s);
		}

		return coverMessage("200", "获取成功", monCounts);
	}

	@ResponseBody
	@RequestMapping("/getCountName")
	public Message getCountName(@RequestBody MonthlyCountFilter filter) {
		List list = MonthlyCountService.getCountName("HB004");
		List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			Object[] obj = (Object[]) list.get(i);
			map.put("name", obj[1]);
			map.put("ID", obj[0]);
			list2.add(map);
		}
		return coverMessage("200", "successful", list2);
	}

	/*@ResponseBody
	@RequestMapping("/testData")  //测试接口 没有用
	public Message getDate(@RequestBody MonthlyCountFilter filter){
		List<MonthlyCount> lists =	MonthlyCountService.getInfoCount(filter.getAab001(),filter.getAab003());
		Map<String , List<MonthlyCount>> map = new HashMap<String, List<MonthlyCount>>();
		Map<String, String> maplist = new HashMap<String, String>();
	//	List<MonthlyCount> data  =new ArrayList<MonthlyCount>();
		List<Map<String, Object>> savedata = new ArrayList<Map<String,Object>>();
		for(MonthlyCount mc:lists){
		if(maplist.isEmpty()){
			maplist.put(mc.getAab003(), mc.getAab003());
		}else {
			if(!mc.getAab003().equals(maplist.get(mc.getAab003()))){
				maplist.put(mc.getAab003(), mc.getAab003());
			}
		}
			if(map.get(mc.getAab003())==null){
				List<MonthlyCount> listmon =new ArrayList<MonthlyCount>();
				listmon.add(mc);
				map.put(mc.getAab003(),listmon);
			}else 
			{
				List<MonthlyCount> lis = map.get(mc.getAab003());
				lis.add(mc);
			//	map.put(mc.getAab003(),listmon);
			}
			
			
		}
		Collection con =maplist.values();
		Iterator ite =con.iterator();
		
		
		while(ite.hasNext())
		{
			Map<String, Object> Onemap =new HashMap<String, Object>();
			

			int i =0,j=0;
			for(MonthlyCount monCount:map.get(ite.next()))
			{
				Map<String, Object> twomap =new HashMap<String, Object>();
				
				if(monCount.getAab005()==null||monCount.getAab005().equals("")){
					Onemap.put("cumlation",DataUtils.isEmpty(monCount.getAab009().trim(), "0") );//累计值到当前月
					Onemap.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty( monCount.getAab010().trim(), "0")  ));//比增
					Onemap.put("oneClassID",monCount.getAab003());//一级分类名
					Onemap.put("oneClassName",DataUtils.isEmpty(monCount.getAab004(), "-")  );//一级分类名称
					Onemap.put("type", "1");
					
				}else if(monCount.getAab005().length()==10)
				{
					i=i+1;

					twomap.put("cumlation",DataUtils.isEmpty(monCount.getAab009().trim(), "0") );//累计值到当前月
					twomap.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty( monCount.getAab010().trim(), "0")  ));//比增
					twomap.put("oneClassID",monCount.getAab003());//一级分类名
					twomap.put("oneClassName",DataUtils.isEmpty(monCount.getAab004(), "-")  );//一级分类名称
					twomap.put("twoClassID", monCount.getAab005());//二级分类ID
					twomap.put("twoClassName",DataUtils.isEmpty(monCount.getAab006().trim(), "-") );//二级分类名称
					twomap.put("type", "2");
					Onemap.put("son"+i, twomap);
				}else if(monCount.getAab005().length()==12)
				{
					j=j+1;
					Map<String, Object> tempmap =new HashMap<String, Object>();
					tempmap.put("cumlation",DataUtils.isEmpty(monCount.getAab009().trim(), "0") );//累计值到当前月
					tempmap.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty( monCount.getAab010().trim(), "0")  ));//比增
					tempmap.put("oneClassID",monCount.getAab003());//一级分类名
					tempmap.put("oneClassName",DataUtils.isEmpty(monCount.getAab004(), "-")  );//一级分类名称
					tempmap.put("twoClassID", monCount.getAab005());//二级分类ID
					tempmap.put("twoClassName",DataUtils.isEmpty(monCount.getAab006().trim(), "-") );
					tempmap.put("type", "3");
					twomap.put("son"+j, tempmap);
				}
				
			}
			
			savedata.add(Onemap);
		}
		
		
		
		
		return coverMessage("200","ok",savedata);
	}*/
	//各个月历史数据
	@ResponseBody
	@RequestMapping("/historyData")
	public Message getHistoryData(@RequestBody MonthlyCountFilter filter) {
		//DataUtils.getValueMonth(judge, filter)
		List list = new ArrayList();
		Map<String, Object> Savemap = new HashMap<String, Object>();

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		String year = sdf.format(new Date());

		//List<MonthlyCount> lists = MonthlyCountService.getHistory(filter.getAab005(), filter.getAab003());
		List<MonthlyCount> lists = MonthlyCountService.getHistory(filter);

		if (lists != null) {
			for (MonthlyCount mc : lists) {
				if (("".equals(mc.getAab010()) || mc.getAab010() == null) && ("".equals(mc.getAab009()) || mc.getAab009() == null)) {
					continue;//按季度来的 没有值 就不要放进去了
				}
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("cumnlative", DataUtils.isEmpty(mc.getAab009(), "-"));
				map.put("currentMonth", DataUtils.isEmpty(mc.getAab016(), "-"));
				map.put("ratio", DataFormateUntil.dataFormat(DataUtils.isEmpty(mc.getAab010(), "0")));
				map.put("month", mc.getBab001());
				list.add(map);
			}
			Savemap.put("unit", lists.get(0).getBab002());
			Savemap.put("twoClassName", DataUtils.isEmpty(lists.get(0).getAab006(), lists.get(0).getAab004()));
			Savemap.put("list", list);
		}

		return coverMessage("200", "successful", Savemap);
	}

//	@ResponseBody
//	@RequestMapping("/NewCount")
//	public Message NewCount( @RequestBody MonthlyCountFilter filter) {
//
////		List<Map<String, Object>> list = new ArrayList<>();//大集合
////		List<Map<String, Object>> listss = new ArrayList<>();//小集合
//		List<Map> twoNames = new ArrayList();
//
//
//		List<MonthlyCount> lists = MonthlyCountService.getTwoClassDatas(filter );
//		for(MonthlyCount mc:lists){
//			Map<String ,Object> map = new HashMap<>();
//			map.put("twoClassId",mc.getAab003());
//			map.put("twoClassName",mc.getAab004());
//			map.put("cumnlative",mc.getAab009());
//			map.put("radio",mc.getAab010());
//			map.put("MonthCumnlative",mc.getAab016());
//			map.put("radioMonth",mc.getAab017());
//			List<Map> listmap = MonthlyCountService.getThirdClassDatas(mc.getAab003(),filter.getBab001());
//			map.put("thirdData",listmap);
//
//
//		}
//
//
//		return coverMessage("200", "successful",twoNames );
//
//}
	@ResponseBody
	@RequestMapping("/CountNames")
	public Message CountNames(@RequestBody MonthlyCountFilter filter)
	{

		String currentMon
		 =MonthlyCountService.getNewMonth("HB002").get(0).toString();


		List listnames = MonthlyCountService.queryCountNames();
		//Map<String , Object> map =new HashMap<String, Object>();
		List  names = new ArrayList<>();
		for (int i = 0; i < listnames.size(); i++) {
			Object[] obj= (Object[]) listnames.get(i);
			Map<String , Object> map =new HashMap<String, Object>();
			map.put("oneClassID",obj[0]);
			map.put("oneClassName", obj[1]);//twoClassID
			map.put("twoClassID", obj[2]);
			map.put("twoClassName", obj[3]);
			map.put("currentMonth", obj[4].toString().length()>4?( obj[4].toString().substring(0, 4)+"年"+obj[4].toString().substring(obj[4].toString().length()-2, obj[4].toString().length())+"月") :obj[4].toString()+"年");
			names.add(map);
		}
		return coverMessage("200", "successful", names);
	}
	
	//map里面数据排序
	public class MapKeyComparator implements Comparator<String>{  
	    public int compare(String str1, String str2) {  
	        return str1.compareTo(str2);  
	    }  
	}
	@ResponseBody
	@RequestMapping("/test")
	public Message getTestData(@RequestBody MonthlyCountFilter filter)
	{
		//filter.setAab001("HB012");
		//filter.setBab001("201804");
		String newmonth = "";
		if ("".equals(filter.getBab001())) {
			List strs = MonthlyCountService.getNewMonth(filter.getAab003());
			newmonth = strs.get(0).toString();
			System.out.println(newmonth);
			filter.setBab001(newmonth);
		}


		  // System.out.println(newmonth);
		List<MonthlyCount> list = MonthlyCountService.getTwoClassDatas(filter);
		List<Map> twoNames = new ArrayList();

		for(MonthlyCount dto : list)
		{
			Map<String ,Object> map = new HashMap<>();
			map.put("title","注：1.规模以上工业指年主营业务收入2000万元及以上的工业。2.工业总产值增幅按价格指数缩减法计算，其余均按现价计算");//注释
				map.put("twoClassId",		StringUtils.isBlank(dto.getAab003())?"": dto.getAab003().trim());
				map.put("twoClassName",		StringUtils.isBlank(dto.getAab004())?"": dto.getAab004().trim());
				map.put("cumnlative",		StringUtils.isBlank(dto.getAab009())?"": dto.getAab009().trim());//累计增长
				map.put("radio",			StringUtils.isBlank(dto.getAab010())?"": dto.getAab010().trim());//比上年同月增长
				map.put("MonthCumnlative",	StringUtils.isBlank(dto.getAab016())?"": dto.getAab016().trim());//当月
				map.put("radioByYear",		StringUtils.isBlank(dto.getAab017())?"": dto.getAab017().trim());//比上年同期增长
				map.put("unit",				StringUtils.isBlank(dto.getBab002())?"": dto.getBab002().trim());//单位
				map.put("increaseByMonth",	StringUtils.isBlank(dto.getAab018())?"": dto.getAab018().trim());//
				map.put("increaseByYear",	StringUtils.isBlank(dto.getAab019())?"": dto.getAab019().trim());//


//     		if(dto.getAab003().endsWith("001")){
//				if(!"".equals(dto.getAab009())||!"".equals(dto.getAab010())||!"".equals(dto.getAab016())||!"".equals(dto.getAab017())){
//					map.put("titleName","工业总产值");//下标注释
//					map.put("titleName2","当前指标占工业总产值比重");//下标注释
//				}else {
//					map.put("titleName","");//下标注释
//					map.put("titleName2","");//下标注释
//				}
//
//			}
//			if(dto.getAab003().endsWith("002")){
//				if(!"".equals(dto.getAab009())||!"".equals(dto.getAab010())||!"".equals(dto.getAab016())||!"".equals(dto.getAab017())){
//					map.put("titleName","工业总产值");//下标注释
//					map.put("titleName2","当前指标占工业总产值比重");//下标注释
//				}else {
//					map.put("titleName","");//下标注释
//					map.put("titleName2","");//下标注释
//				}
//			}

			List<Map> listmap = MonthlyCountService.getThirdClassDatas(dto.getAab003(),filter.getBab001());
			if (ObjectUtils.isNotBlank(listmap)){
				if(!"".equals(dto.getAab009())||!"".equals(dto.getAab010())||!"".equals(dto.getAab016())||!"".equals(dto.getAab017())){
					map.put("titleName",dto.getAab004().trim());
					map.put("titleName2","当前指标占"+dto.getAab004()+"比重");
				}
			}
			map.put("thirdData",listmap);
			map.put("date",dto.getBab001().trim());

			System.out.print(listmap.toString());

			twoNames.add(map);
		}

		return  coverMessage("200","successful",twoNames);
	}

}
